package com.central.scheduler.dao.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.central.common.model.SuperEntity;
import com.central.scheduler.common.enums.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

/**
 * @author Tindy
 * @date 2021/11/5
 * @describe
 */
@Data
@TableName("sch_error_command")
public class ErrorCommand extends SuperEntity {

    /**
     * command type
     */
    private CommandType commandType;

    /**
     * process definition code
     */
    private long processDefinitionCode;

    /**
     * user id
     */
    private long userId;
    private String username;

    /**
     * project id
     */
    private long proId;
    private String proName;

    /**
     * command parameter, format json
     */
    private String commandParam;

    /**
     * task depend type
     */
    private TaskDependType taskDependType;

    /**
     * failure strategy
     */
    private FailureStrategy failureStrategy;

    /**
     *  warning type
     */
    private WarningType warningType;

    /**
     * warning group id
     */
    private Long warningGroupId;

    /**
     * schedule time
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date scheduleTime;

    /**
     * start time
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date startTime;

    /**
     * process instance priority
     */
    private Priority processInstancePriority;

    /**
     * 执行信息
     */
    private String message;

    /**
     * dry run flag
     */
    private int dryRun;

    public ErrorCommand() {}

    public ErrorCommand(Command command, String message) {
        setId(command.getId());
        this.commandType = command.getCommandType();
        this.userId = command.getUserId();
        this.username=command.getUsername();
        this.proId=command.getProId();
        this.proName=command.getProName();
        this.processDefinitionCode = command.getProcessDefinitionCode();
        this.commandParam = command.getCommandParam();
        this.warningType = command.getWarningType();
        this.warningGroupId = command.getWarningGroupId();
        this.scheduleTime = command.getScheduleTime();
        this.taskDependType = command.getTaskDependType();
        this.failureStrategy = command.getFailureStrategy();
        this.startTime = command.getStartTime();
        this.processInstancePriority = command.getProcessInstancePriority();
        this.message = message;
        this.dryRun = command.getDryRun();
        setCreateTime(command.getCreateTime());
        setUpdateTime(command.getUpdateTime());
    }
}
